package main

var result [][]int

// https://blog.csdn.net/lemon_tree12138/article/details/50986990

func permute(nums []int) [][]int {
	result = nil
	doPermute(nums, 0, len(nums)-1)
	return result
}

func doPermute(arr []int, cursor int, end int) {
	if cursor == end {
		item := make([]int, len(arr))
		copy(item, arr)
		result = append(result, item)
	} else {
		for i := cursor; i <= end; i++ {
			arr[cursor], arr[i] = arr[i], arr[cursor]
			doPermute(arr, cursor+1, end)
			arr[cursor], arr[i] = arr[i], arr[cursor]
		}
	}
}

func main() {
	r := permute([]int{1, 2, 3})
	println(r)
}
